package com.alawn.framework.core.web.faces.event;

import javax.faces.component.UIViewRoot;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import com.alawn.framework.core.web.faces.controller.FacesController;

/**
 * @Description
 * @auther johnny
 * @create 2019-02-12 11:14
 */
public class ControllerPhaseListener implements PhaseListener {

    private static final long serialVersionUID = -4016428550782703448L;

    @Override
    public void beforePhase(PhaseEvent event) {
        UIViewRoot view = event.getFacesContext().getViewRoot();
        if (view.getViewMap(false) == null) {
            FacesController controller = FacesController.getCurrentInstance();
            if (controller != null) {
                controller.onEntry();
            }
        }
    }

    @Override
    public void afterPhase(PhaseEvent event) {
    }


    @Override
    public PhaseId getPhaseId() {
        return PhaseId.RENDER_RESPONSE;
    }

}
